//
//  BasicViewController.m
//  DebugDemo
//
//  Created by XFB on 2018/11/8.
//  Copyright © 2018年 ZhouCheng. All rights reserved.
//

#import "BasicViewController.h"
#import "BasicList.h"
#import "BasicDescribeCell.h"

#import "StrongOrCopyViewController.h"
#import "CrashViewController.h"
#import "LayoutViewController.h"
#import "KVCViewController.h"
#import "KVOViewController.h"
#import "MVPViewController.h"
#import "MVVMViewController.h"
#import "MyProfileViewController.h"
#import "GCDViewController.h"
#import "BlockViewController.h"
#import "RunLoopViewController.h"
#import "AspectsViewController.h"
#import "TopicDetailViewController.h"
#import "StarViewController.h"
#import "CommentViewController.h"
#import "LoginRegisterViewController.h"
#import "ChooseViewController.h"
#import "DropViewController.h"
#import "MVPCountViewController.h"
#import "MVVMTableViewController.h"
#import "AnswerViewController.h"
#import "BezierViewController.h"
#import "ShopListViewController.h"
#import "ShadowViewController.h"
#import "ComplexChooseViewController.h"
#import "WaterFallViewController.h"
#import "SocketViewController.h"

@interface BasicViewController () <UITableViewDataSource, UITableViewDelegate>

@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (nonatomic, strong) NSMutableArray *dataSource;

@end

@implementation BasicViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    [self setupBasicSet];
    [self setupUI];
}

- (void)setupBasicSet
{
    self.view.backgroundColor = [UIColor whiteColor];
}

- (void)setupUI
{
    self.tableView.rowHeight = 50;
    [self.tableView registerNib:[UINib nibWithNibName:@"BasicDescribeCell" bundle:nil] forCellReuseIdentifier:@"BasicDescribeCell"];
    [self.tableView reloadData];
    
    if (@available(iOS 11.0, *)) {
        self.tableView.estimatedRowHeight = 0;
        self.tableView.estimatedSectionFooterHeight = 0;
        self.tableView.estimatedSectionHeaderHeight = 0;
        self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    } else {
        self.automaticallyAdjustsScrollViewInsets = NO;
    }
}

#pragma mark --- <UITableViewDataSource>

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.dataSource.count;
}

#pragma mark --- <UITableViewDelegate>
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    BasicDescribeCell *cell = [tableView dequeueReusableCellWithIdentifier:@"BasicDescribeCell"];
    cell.basicList = self.dataSource[indexPath.row];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    BasicList *baseListM = self.dataSource[indexPath.row];
    
    if (indexPath.row == 0) { // Copy和Strong修饰NSString
        StrongOrCopyViewController *vc = [[NSBundle mainBundle] loadNibNamed:@"StrongOrCopyViewController" owner:nil options:nil].firstObject;
        vc.titleString = baseListM.title;
        [self.navigationController pushViewController:vc animated:YES];
    } else if (indexPath.row == 1) { // App奔溃的多种类型
        CrashViewController *vc = [[NSBundle mainBundle] loadNibNamed:@"CrashViewController" owner:nil options:nil].firstObject;
        vc.titleString = baseListM.title;
        [self.navigationController pushViewController:vc animated:YES];
    } else if (indexPath.row == 2) { // iOS布局管理解密
        LayoutViewController *vc = [[NSBundle mainBundle] loadNibNamed:@"LayoutViewController" owner:nil options:nil].lastObject;
        vc.titleString = baseListM.title;
        [self.navigationController pushViewController:vc animated:YES];
    } else if (indexPath.row == 3) { // KVC剖析
        KVCViewController *vc = [[KVCViewController alloc] init];
        vc.titleString = baseListM.title;
        [self.navigationController pushViewController:vc animated:YES];
    } else if (indexPath.row == 4) { // KVO剖析
        KVOViewController *vc = [[KVOViewController alloc] init];
        vc.titleString = baseListM.title;
        [self.navigationController pushViewController:vc animated:YES];
    } else if (indexPath.row == 5) { // MVP面向协议
        MVPViewController *vc = [[MVPViewController alloc] init];
        [self.navigationController pushViewController:vc animated:YES];
    } else if (indexPath.row == 6) { // MVVM
        MVVMViewController *vc = [[MVVMViewController alloc] init];
        [self.navigationController pushViewController:vc animated:YES];
    } else if (indexPath.row == 7) { // 个人中心
        MyProfileViewController *vc = [[MyProfileViewController alloc] init];
        [self.navigationController pushViewController:vc animated:YES];
    } else if (indexPath.row == 8) { // 剖析GCD
        GCDViewController *vc = [[GCDViewController alloc] init];
        [self.navigationController pushViewController:vc animated:YES];
    } else if (indexPath.row == 9) { // Block
        BlockViewController *vc = [[BlockViewController alloc] init];
        [self.navigationController pushViewController:vc animated:YES];
    } else if (indexPath.row == 10) { // RunLoop
        RunLoopViewController *vc = [[RunLoopViewController alloc] init];
        [self.navigationController pushViewController:vc animated:YES];
    } else if (indexPath.row == 11) { // Aspects
        AspectsViewController *vc = [[AspectsViewController alloc] init];
        [self.navigationController pushViewController:vc animated:YES];
    } else if (indexPath.row == 12) { // 话题详情
        TopicDetailViewController *vc = [[TopicDetailViewController alloc] init];
        [self.navigationController pushViewController:vc animated:YES];
    } else if (indexPath.row == 13) { // 五星评分
        StarViewController *vc = [[StarViewController alloc] init];
        [self.navigationController pushViewController:vc animated:YES];
    } else if (indexPath.row == 14) { // 底部输入框
        CommentViewController *vc = [[CommentViewController alloc] init];
        [self.navigationController pushViewController:vc animated:YES];
    } else if (indexPath.row == 15) { // 登录注册
        LoginRegisterViewController *vc = [[LoginRegisterViewController alloc] init];
        [self.navigationController pushViewController:vc animated:YES];
    } else if (indexPath.row == 16) { // 单选OR多选
        ChooseViewController *vc = [[ChooseViewController alloc] init];
        [self.navigationController pushViewController:vc animated:YES];
    } else if (indexPath.row == 17) { // 下拉菜单
        DropViewController *vc = [[DropViewController alloc] init];
        [self.navigationController pushViewController:vc animated:YES];
    } else if (indexPath.row == 18) { // MVP 计数器
        MVPCountViewController *vc = [[MVPCountViewController alloc] init];
        [self.navigationController pushViewController:vc animated:YES];
    } else if (indexPath.row == 19) { // MVVM Demo
        MVVMTableViewController *vc = [[MVVMTableViewController alloc] init];
        [self.navigationController pushViewController:vc animated:YES];
    } else if (indexPath.row == 20) { // MVP Networking
        AnswerViewController *vc = [[AnswerViewController alloc] init];
        [self.navigationController pushViewController:vc animated:YES];
    } else if (indexPath.row == 21) { // Bezier
        BezierViewController *vc = [[BezierViewController alloc] init];
        [self.navigationController pushViewController:vc animated:YES];
    } else if (indexPath.row == 22) { // 商品列表List
        ShopListViewController *vc = [[ShopListViewController alloc] init];
        [self.navigationController pushViewController:vc animated:YES];
    } else if (indexPath.row == 23) { // 阴影shadow
        ShadowViewController *vc = [[ShadowViewController alloc] init];
        [self.navigationController pushViewController:vc animated:YES];
    } else if (indexPath.row == 24) { // 复杂多选
        ComplexChooseViewController *vc = [[ComplexChooseViewController alloc] init];
        [self.navigationController pushViewController:vc animated:YES];
    } else if (indexPath.row == 25) {
        WaterFallViewController *vc = [[WaterFallViewController alloc] init];
        [self.navigationController pushViewController:vc animated:YES];
    } else if (indexPath.row == 26) {
        SocketViewController *vc = [[NSBundle mainBundle] loadNibNamed:@"SocketViewController" owner:nil options:nil].firstObject;
//        SocketViewController *vc = [[SocketViewController alloc] init];
        vc.titleString = baseListM.title;
        [self.navigationController pushViewController:vc animated:YES];
    }

}

#pragma mark --- <Lazy loading>

- (NSMutableArray *)dataSource
{
    if (_dataSource == nil) {
        NSString *plistPath = [[NSBundle mainBundle] pathForResource:@"BasicList.plist" ofType:nil];
        NSArray *plistArray = [NSArray arrayWithContentsOfFile:plistPath];
        NSArray *modelArray = [BasicList mj_objectArrayWithKeyValuesArray:plistArray];
        _dataSource = [modelArray mutableCopy];
    }
    return _dataSource;
}

@end
